package com.kws.merchant.service.impl;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.kws.common.config.constant.MinioCommonBucket;
import com.kws.merchant.domain.LoansInsurance;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.merchant.domain.po.LoansInsurancePo;
import com.kws.merchant.mapper.LoansInsuranceMapper;
import com.kws.merchant.service.LoansInsuranceService;
import com.kws.merchant.util.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * 贷款-保险(LoansInsurance)表服务实现类
 *
 * @author yxy
 * @since 2024-10-29 14:45:42
 */
@Service("loansInsuranceService")
public class LoansInsuranceServiceImpl extends ServiceImpl<LoansInsuranceMapper, LoansInsurance> implements LoansInsuranceService {

    @Resource
    private LoansInsuranceMapper loansInsuranceMapper;

    @Value("${minio.ENDPOINT}")
    private String minioUrl;

    /**
     * 分页查询列表
     */
    @Override
    public Page<LoansInsurance> pageList(LoansInsurancePo loansInsurancePo) {
        Page<LoansInsurance> page = new Page<>(loansInsurancePo.getPageSize(), loansInsurancePo.getTotalPage());
        LambdaQueryWrapper<LoansInsurance> queryWrapper = Wrappers.lambdaQuery();
        String name = loansInsurancePo.getName();//机构名称
        String organization = loansInsurancePo.getOrganization();//机构名称
        Integer type = loansInsurancePo.getType();
        if (StringUtils.isNotEmpty(name)){
            queryWrapper.eq(LoansInsurance::getName,name);
        }
        if (StringUtils.isNotEmpty(organization)){
            queryWrapper.eq(LoansInsurance::getOrganization,organization);
        }
        queryWrapper.eq(LoansInsurance::getType,type);
        Page<LoansInsurance> page1 = this.page(page, queryWrapper);
        List<LoansInsurance> records = page1.getRecords();
        records.forEach(x->{
            x.setImg(FileUtil.fixFileName()+x.getImg());
        });
        return page1;
    }

    @Override
    public LoansInsurance detailById(Long id) {
        LoansInsurance loansInsurance = this.getById(id);
        loansInsurance.setApplicantPool(FileUtil.fixFileName()+loansInsurance.getImg());
        return loansInsurance;
    }


}
